class Star_field {

  ArrayList fields_list;
  int number_of_fields;
  
  Star_field() {  
    fields_list = new ArrayList();
  }


  void add_field(int number_of_stars,float velocity,float radius,color cc) {
    fields_list.add(new Star_group(number_of_stars,velocity,radius,cc));
    number_of_fields++;
  }

  void math() {
    Star_group star_group;
    for(int x=0;x<number_of_fields;x++) {
      star_group =  (Star_group)fields_list.get(x);
      star_group.math();
    }
  }

  void render() {

    Star_group star_group;
    for(int x=0;x<number_of_fields;x++) {
      star_group =  (Star_group)fields_list.get(x);
      star_group.render();
    }
  }


  class Star_group {

    Star[] stars;
    int number_of_stars;

    Star_group(int number_of_stars, float velocity,float radius,color cc) {
  
        stars = new Star[number_of_stars]; 
      this.number_of_stars = number_of_stars;
      for(int x=0;x<number_of_stars;x++) {
        stars[x] = new Star(velocity,radius,cc);
      }
    }

    void math() {
      for(int x=0;x<number_of_stars;x++) {
        stars[x].math();
      }
    }

    void render() {
      for(int x=0;x<number_of_stars;x++) {
        stars[x].render();
      }
    }


    class Star {
      float x_loc;
      float y_loc;

      float velocity;
      float radius;
      color cc;

      Star(float velocity,float radius,color cc) {
        this.cc = cc;
        this.velocity = velocity;
        this.radius   = radius;
        x_loc = random(0,width);
        y_loc = random(0,height);
      }

      void math() {

        if(x_loc < -5) {
          x_loc = width+5;
        }

        x_loc = x_loc - velocity;
      }

      void render() {
        fill(cc);
        rect(x_loc,y_loc,radius,radius);
      }
    }
  }
}

